<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ page isELIgnored="false"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<TITLE>登录页面</TITLE>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery-1.8.0.min.js"></script>
<script src="${pageContext.request.contextPath}/styles/management/js/jquery-1.4.4.min.js" type="text/javascript"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/plugins/artdialog/artDialog.js"></script>
<link href="${pageContext.request.contextPath}/css/main.css" rel="stylesheet" type="text/css" />
<link href="${pageContext.request.contextPath}/plugins/artdialog/skins/blue.css" rel="stylesheet"
	type="text/css" />
<script language="javascript">
	function checkInput() {
		var uname = $("#user_name").val();
		var upassword = $("#user_password").val();
		if (uname == "") {
			myTips('用户名称不能为空');
			return;
		}
		if (upassword == "") {
			myTips('用户密码不能为空');
			return;
		}
		//alert('hell');
		$("#loginfrm").submit();
	}
	function myTips(str) {
		art.dialog({
			title : '操作提示',
			content : str,
			lock : true
		});
	}

	function add_Cookies() {
		var name = $("#user_name").val();
		var value = $("#user_password").val();
		//删除原来的cookie
		//设置cookie过期时间  3天
		var str = name + "=" + escape(value);
		var date = new Date();
		date.setTime(date.getTime() + (3 * 24 * 60 * 60 * 1000));
		str += "; expires=" + date.toGMTString();
		//$.cookie(name,value,{path: '/', expires: date });
		document.cookie = str;

	}
	function get_Cookie() {
		var name = $("#user_name").val();
		var psd = "";
		var arrStr = document.cookie.split("; ");
		for ( var i = 0; i < arrStr.length; i++) {
			var temp = arrStr[i].split("=");
			if (temp[0] == name)
				psd = unescape(temp[1]);
		}
		if (psd != "") {
			$("#user_password").val(psd);
		}
	}
	function set_Cookie() {
		var check = $("#check").attr("checked");
		var name = $("#user_name").val();
		var value = $("#user_password").val();
		if (name == "") {
			myTips("请先输入用户名！");
			$("#user_name").focus();
			$("#check").attr("checked", false);
			return;
		}
		if (value == "") {
			myTips("请先输入密码！");
			$("#user_password").focus();
			$("#check").attr("checked", false);
			return;
		}

		if (check) {
			add_Cookies();
		}

	}
	function del_cookie(name) {
		var date = new Date();
		date.setTime(date.getTime() - 1);
		var arr = document.cookie.match(new RegExp("(^| )" + name
				+ "=([^;]*)(;|$)"));
		if (arr != null) {
			var cval = unescape(arr[2]);
			if (cval != null) {
				document.cookie = name + "=" + cval + ";expires="
						+ exp.toGMTString();
			}
		}
	}
</script>
</head>

<body style="background-color:#CDDCF2;">
	<s:if test="message!='' && message!=null">
		<script language="javascript">
			art.dialog({
				title : '错误提示',
				content : '${message}',
				lock : true
			});
		</script>
	</s:if>
	<div id="info">
		<div id="center">

			<div class="loginfrom">
				<form action="${pageContext.request.contextPath}/test/login.do" method="post" id="loginfrm"
					name="loginfrm">
					<div class="loginlabel">
						<label>用户名</label><br /> <input class="logininput"
							name="userName"
							value="<s:property value="userName"/>" id="user_name"
							type="text" onchange="get_Cookie();" />
					</div>
					<div class="loginlabel">
						<label>密码</label><br /> <input class="logininput"
							name="password"
							value="<s:property value="password"/>"
							id="user_password" type="password" />
					</div>

					<div class="loginbt clearfix">
						<div class="zt">
							<input name="check" type="checkbox" value="" id="check"
								onchange="set_Cookie();" /> 记住登陆状态
						</div>

						<div class="an">
							<input name="" type="button" value=" " onclick="checkInput();" />
						</div>
					</div>
				</form>
			</div>
		</div>
	</div>
</body>
</html>
